package com.htrq.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.htrq.dao.JQhistoryDao;
import com.htrq.entity.JQHistory;
import com.htrq.entity.Page;
import com.htrq.entity.TotalMoney;

@Service
@Transactional(value="txManager2")
public class JQhistoryService {
	
	@Resource
	private JQhistoryDao jqHDao;
	
	public Long getTotal(JQHistory jqh) {
		return (long) jqHDao.getTotal(jqh);
	}

	public List<JQHistory> getAlljqh(JQHistory jqh, Page page) throws ParseException {
		//TODO Auto-generated method stub
		List<Object[]> list=jqHDao.getAlljqh(jqh,page);
		List<JQHistory> jqhs=new ArrayList<JQHistory>();
		for(Object[] obj:list){
			JQHistory jqh2=new JQHistory();
			jqh2.setAutoId(obj[0].toString());
			jqh2.setDeptId(obj[1].toString());
			jqh2.setMachineId(obj[2].toString());
			jqh2.setStarttime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(obj[3].toString()));
			jqh2.setCardNumber(obj[4].toString());
			jqh2.setCname(obj[5].toString());
			jqh2.setIDcard(obj[6].toString());
			jqh2.setTel(obj[7].toString());
			jqh2.setVehicleId(obj[8].toString());
			jqh2.setVehicleType(obj[9].toString());
			jqh2.setLastBalance(Double.parseDouble(obj[10].toString()));
			jqh2.setTotalNum(obj[11].toString());
			jqh2.setPrice(obj[12].toString());
			jqh2.setMoney(Double.parseDouble(obj[13].toString()));
			jqh2.setCurrBalance(Double.parseDouble(obj[14].toString()));
			jqh2.setCompany(obj[15].toString());
			jqh2.setCardType(obj[16].toString());
			jqhs.add(jqh2);
		}
		return jqhs;
	}

	public TotalMoney getMoneyandNum(JQHistory jqh) {
		//TODO Auto-generated method stub
		List<Object[]> list=jqHDao.getMoneyandNum(jqh);
		TotalMoney tot=new TotalMoney();
		tot.setAmount(list.get(0)[0].toString());
		tot.setMoney(list.get(0)[1].toString());
		return tot;
	}
}
